<?php
if (!defined('THINK_PATH')) exit();

	class selectModel{
		public function getMainMod(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			$db = M('Model');
			$sql = "select `z_url` 'url',`z_name` 'name',`z_id` 'mod' from `zjx_module_admin` where `z_belong`=0 and `z_showmod`>1 order by `z_grade`";
			$mainMod = $db->query($sql);
			
//			$mainMod = array(
//				array('url'=>'http://www.baidu.com','name'=>'公司介绍','mod'=>1),
//			);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$mainMod);
			}
			return $mainMod;
		}
		public function getFootMod(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			$db = M('Model');
			$sql = "select `z_url` 'url',`z_name` 'name',`z_id` 'mod' from `zjx_module_admin` where `z_belong`=0 and `z_showmod`>1 and `z_showmod` not in(3)  order by `z_grade`";
			$mainMod = $db->query($sql);
			
//			$mainMod = array(
//				array('url'=>'http://www.baidu.com','name'=>'公司介绍','mod'=>1),
//			);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$mainMod);
			}
			return $mainMod;
		}
		public function getModSon(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			$db = M('Model');
			$sql = "select `z_url` 'url',`z_name` 'name',`z_belong` 'mod',`z_id` 'modid' from `zjx_module_admin` where `z_belong`>0 order by `z_grade`";
			$secondMod = $db->query($sql);
			
//			$secondMod = array(
//				array('url'=>'http://www.baidu.com','name'=>'百度1','mod'=>1),
//			);

			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,json_encode($secondMod));
			}
			echo json_encode($secondMod);
		}
		
		public function getAllLinks(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select l_mark mark,l_name name,l_url url from `zjx_links`";
			$db = M('Model');
			$links = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$links);
			}
			return $links;
		}
		public function getAllSonModInfoById($id){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$id);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_module_admin` where `z_belong`=".$id." and `z_belong`>0 order by z_belong,z_grade";
			$db = M('Model');
			$ret = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$id,$ret);
			}
			return $ret;
		}
		public function getModInfoById($id){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$id);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_module_admin` where `z_id`=".$id;
			$db = M('Model');
			$modinfo = $db->query($sql);
			
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$id,$modinfo[0]);
			}
			return $modinfo[0];
		}
		
		public function getModConInfoByMid($mid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$mid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_content` where `c_mid`=".$mid;
			$db = M('Model');
			$content = $db->query($sql);
			$content = $content[0];
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$mid,$content);
			}
			return $content;
		}
		
		public function getAritcleTitByMid($mid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$mid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select a_id tid,a_title title,a_time time from `zjx_article` where `a_mid`=".$mid;
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$mid,$content);
			}
			return $content;
		}
		public function getAritcleInfoById($tid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$mid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_article` where `a_id`=".$tid;
			$db = M('Model');
			$content = $db->query($sql);
			$content = $content[0];
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$tid,$content);
			}
			return $content;
		}
		public function getProductTitByMid($mid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$mid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select p_id,p_name,p_code,p_info,p_image,p_mid from `zjx_product` where `p_mid`=".$mid;
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$mid,$content);
			}
			return $content;
		}
		public function getProconInfoById($pid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$pid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_product` where `p_id`=".$pid;
			$db = M('Model');
			$content = $db->query($sql);
			$content = $content[0];
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$pid,$content);
			}
			return $content;
		}
		public function getProattrInfoById($pid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$pid);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_proattr` where `a_pid`=".$pid.' order by a_grade';
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$pid,$content);
			}
			return $content;
		}
		public function insertMsg($updarr){
			foreach ($updarr as $k=>$v){
				$keys .= '`'.$k.'`,';
				$values .= '\''.$v.'\',';
			}
			$keys = rtrim($keys,',');
			$values = rtrim($values,',');
			$sql = 'insert into `zjx_msgboard` ('.$keys.') values('.$values.')';
			$db = M('Model');
			return $db->execute($sql);
		}
		public function getRecomments(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			$sql = 'select * from `zjx_product` where `p_isshow`=1 order by p_time';
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$content);
			}
			return $content;
		}
		public function getPosters(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__,600);
			if($cache && C('HZY_CACHE'))return $cache;
			$sql = 'select * from `zjx_poster` where `p_state`=1 and `p_end`>\''.date('Y-m-d H:i:s').'\'';
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$content);
			}
			return $content;
		}
		public function getWebBasicInfo(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_basicinfo`";
			$db = M('Model');
			$content = $db->query($sql);
			$content = $content[0];
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$content);
			}
			return $content;
		}
		public function getAllShowCon(){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__);
			if($cache && C('HZY_CACHE'))return $cache;
			
			$sql = "select * from `zjx_module_admin` where `z_show`=2 order by `z_grade`";
			$db = M('Model');
			$content = $db->query($sql);
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__,$content);
			}
			return $content;
		}
		public function getRootModByMid($mid){
			$cache = cacheModel::getCache(__CLASS__,__FUNCTION__.$mid);
			if($cache && C('HZY_CACHE'))return $cache;
			$sql = "select * from `zjx_module_admin` where `z_id`=".$mid;
			$db = M('Model');
			$content = $db->query($sql);
			$content = $content[0];
			while ($content['z_belong'] > 0){
				$mid = $content['z_belong'];
				$sql = "select * from `zjx_module_admin` where `z_id`=".$mid;
				$content = $db->query($sql);
				$content = $content[0];
			}
			if(C('HZY_CACHE')){
				cacheModel::addCache(__CLASS__,__FUNCTION__.$mid,$content);
			}
			return $content;
		}
	}